import request from '@/request'

const API = {
  /**一键登录 */
  ['LOGIN_SILENT']: '/api/login/oneClickLogin',
  /**手机号密码登录 */
  ['LOGIN_PASSWORD']: '/api/login/login',
  /**手机号验证码登录 */
  ['LOGIN_CAPTCHA']: '/api/login/codeLogin',
  /**获取验证码 */
  ['GET_CAPTCHA']: '/api/pub/send_sms',
  /**忘记密码 */
  ['FORGET_PASSWORD']: '/api/login/passwordForget',
  /**修改手机号 */
  ['EDIT_PHONE_NUMBER']: '/api/login/phoneEdit',
  /**修改密码 */
  ['EDIT_PASSWORD']: '/api/login/passwordEdit'
}

/**
 * 微信获取手机号码一键登录
 */
export const loginBySilent = data =>
  request({
    url: API.LOGIN_SILENT,
    data
  })

/**
 * 手机号密码登录
 */
export const loginByPassword = data =>
  request({
    url: API.LOGIN_PASSWORD,
    data
  })

/**
 * 手机号验证码登录
 */
export const loginByCaptcha = data =>
  request({
    url: API.LOGIN_CAPTCHA,
    data
  })

/**
 * 忘记密码
 */
export const forgetPassword = data =>
  request({
    url: API.LOGIN_CAPTCHA,
    data
  })

/**
 * @description 获取手机号验证码
 * @param {string} phone 手机号
 */
export const fetchSMSCaptcha = phone =>
  request({
    url: API.GET_CAPTCHA,
    data: { phone }
  })

/**
 * @description 修改手机号码
 * @param {string} phone 手机号
 * @param {string} code 手机号验证码
 */
export const editPhoneNumber = (phone, code) =>
  request({
    url: API.EDIT_PHONE_NUMBER,
    data: { phone, code }
  })

/**
 * @description 修改登录密码
 */
export const editPassword = data =>
  request({
    url: API.EDIT_PASSWORD,
    data
  })
